package com.yong.android.framework.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 滑动可控的VP
 *
 * @Author: yong
 * @E-mail: 775811790@qq.com
 * @CreateDate: 2017/12/19 0:41
 * @UpdateRemark: [说明本次修改内容]
 * @Version: 1.0.0
 */
public class SlideControlableViewPager extends ViewPager{
    private boolean mIsPagingEnabled = true;

    public SlideControlableViewPager(Context context) {
        super(context);
    }

    public SlideControlableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.mIsPagingEnabled && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return this.mIsPagingEnabled && super.onInterceptTouchEvent(event);
    }

    public void setPageSlideEnabled(boolean b) {
        this.mIsPagingEnabled = b;
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        boolean smooth = smoothScroll;
        if(!mIsPagingEnabled) {
            smooth = false;
        }
        super.setCurrentItem(item, smooth);
    }
}
